package model

import "gorm.io/gorm"

// 收藏歌单模型
type LikePlaylist struct {
	gorm.Model
	Uid      string //用户Id
	Pid      string //歌单id
	Platform string
	PicUrl   string
	IsImport bool
	Name     string
}

// 收藏歌曲模型
type LikeSong struct {
	gorm.Model
	Uid      string //用户Id
	Sid      string //歌曲id
	Pid      string //收藏在的歌单Id
	Platform string
	Name     string
	Singer   string
	Hash     string //酷狗专用
	Album    string
}

// //判断当前用户下该歌单Id是否存在
// func isExistPlaylist(uid, pid string) bool {
// 	var likePlaylist LikePlaylist
// 	num := DB.Where("uid = ? and pid = ?", uid, pid).First(&likePlaylist)
// 	if num.RowsAffected > 0 {
// 		return true
// 	} else {
// 		return false
// 	}
// }

// //判断当前用户下该歌单歌曲是否存在
// func isExistSong(uid, sid, pid string) bool {
// 	var likeSong LikeSong
// 	num := DB.Where("uid = ? and sid = ? and pid = ", uid, sid, pid).First(&likeSong)
// 	if num.RowsAffected > 0 {
// 		return true
// 	} else {
// 		return false
// 	}
// }

//查询当前用户下有哪些已经上传的歌单
func ExistPlaylist(uid string) []LikePlaylist {
	var likePlaylist []LikePlaylist
	DB.Model(&LikePlaylist{}).Where("uid = ?", uid).Find(&likePlaylist)
	return likePlaylist
}

//查询当前用户下有哪些已经上传的歌曲
func ExistSong(uid string) []LikeSong {
	var likeSong []LikeSong
	DB.Model(&LikeSong{}).Where("uid = ?", uid).Find(&likeSong)
	return likeSong
}

//删除全部收藏歌单
func DeleteAllPlaylist(uid string) {
	DB.Delete(&LikePlaylist{}, "uid LIKE ?", "%"+uid+"%")
}

//删除全部收藏歌曲
func DeleteAllSong(uid string) {
	DB.Delete(&LikeSong{}, "uid LIKE ?", "%"+uid+"%")
}
